/*
 * ExtListFilenameFilter.java
 *
 * Created on February 19, 2006, 11:07 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package custom.io;

import java.io.File;
import java.io.FilenameFilter;
import java.util.LinkedList;
import java.util.Collection;

/**
 *
 * @author David Armstrong
 */
public class ExtListFilenameFilter implements FilenameFilter {

    private LinkedList<String> extList = null;

    /**
     * Creates a new instance of ExtListFilenameFilter
     */
    public ExtListFilenameFilter() {
        extList = new LinkedList<String>();
    }

    public ExtListFilenameFilter(Collection<String> c) {
        extList = new LinkedList<String>(c);
    }

    public boolean accept(File directory, String fileName) {
        boolean status = true;

        // If the file is a directory, do NOT do the extension filter on it.
        if ((extList != null) && (!new File(directory.toString() + System.getProperty("file.separator") + fileName).isDirectory())) {
            status = false;
            for (String ext : extList) {
                if (status = fileName.endsWith(ext)) {
                    break;
                }
            }
        }

        return status;
    }

    public LinkedList<String> getExtList() {
        return extList;
    }
}
